package com.zhongyu.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhongyu.pojo.Order;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

public interface OrderMapper extends BaseMapper<Order> {
    @Select("select * from smbms_order")
    List<Order> findAll();
    @Select("UPDATE smbms_order SET state=#{state} ,stock_TIME=#{stocktime},stock_keeper=#{stockeeper} where id=#{id} ")
   void updatebu(@Param("state") Integer state,@Param("stockeeper") Integer stockKeeper,@Param("stocktime") LocalDateTime StockTime,@Param("id") Integer orderId);
    @Select("UPDATE smbms_order SET state=#{state} ,purchase_TIME=#{purchaseTime} where id=#{id} and type=1")
    void update(@Param("state")String state, @Param("purchaseTime")LocalDateTime purchaseTime,@Param("id") Integer id);

/*    @Select("SELECT t1.*, t2.pro_Name FROM smbms_order t1 JOIN smbms_provider t2 ON t1.provider_id=t2.id WHERE state=1 AND TYPE=1")
    @ResultMap("omRm")
    List<Order> searchAll(Page page, @Param("ew") Wrapper wrapper);*/

    @Select("SELECT t1.*, t2.pro_Name,t3.username FROM smbms_order t1 JOIN smbms_provider t2 ON t1.provider_id=t2.id JOIN smbms_user t3 ON t1.creator AND t1.CHECKER AND t1.purchaser=t3.id  WHERE state=1 AND TYPE=1")
    @ResultMap("omRm")
    List<Order> searchAll(Page page);

    @Select("SELECT t1.*, t2.pro_Name, t3.username FROM smbms_order t1 JOIN smbms_provider t2 ON t1.provider_id=t2.id  JOIN smbms_user t3 ON t1.purchaser =t3.id WHERE TYPE=2")
    @ResultMap("omRm")
    List<Order> searchSal(Page page);
    @Select("SELECT MAX(id) FROM smbms_order")
       Integer selectId();


}
